package com.wad.common.exception;

import com.wad.vo.common.Result;
import com.wad.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wad
 * @date 2023/11/29 15:37
 * @project e-commerce
 **/

@ControllerAdvice
public class GlobalExceptionHandler {





    //全局异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }

    //自定义异常处理
    @ExceptionHandler(BussinessException.class)
    @ResponseBody
    public Result error(BussinessException exception){
        return Result.build(null,exception.getResultCodeEnum());
    }
}
